import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import VueRouter from 'unplugin-vue-router/vite'
import Layouts from 'vite-plugin-vue-layouts'
import Icons from 'unplugin-icons/vite'
import AutoImport from 'unplugin-auto-import/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite'
import  UnpluginVueI18n  from '@intlify/unplugin-vue-i18n/vite'
import viteCompression from 'vite-plugin-compression'
import { DirResolverHelper } from 'vite-auto-import-resolvers'
import {
	ElementPlusResolver,
    VueUseComponentsResolver
} from 'unplugin-vue-components/resolvers'
import { AutoImportResolvers } from '../shared/resolvers'

export default () => ([
    // vue 官方插件，用来解析 sfc
    vue(),
    // tsx 支持
	vueJsx(),
    // 开发devtools
    vueDevTools(),
    VueRouter({
        routesFolder: [
            {
                src: resolve(__dirname, '../../src/pages'),
                path: ''
            },
        ],
        extensions: ['.vue'],
        dts: './presets/types/typed-router.d.ts',
    }),
    Layouts(),
    // https://icones.netlify.app/
    Icons({
        autoInstall: true,
    }),
    DirResolverHelper(),
    AutoImport({
        dts: './presets/types/auto-imports.d.ts',
        dirs: ['src/stores', 'src/api/modules'],
        imports: ['vue', '@vueuse/core', 'pinia', 'vue-router', 'vue-i18n'],
        resolvers: AutoImportResolvers(),
        eslintrc: {
            enabled: true,
            globalsPropValue: true,
            filepath: 'presets/eslint/.eslintrc-auto-import.json',
        }
    }),
    // 组件自动按需引入
	Components({
        extensions: ['vue', 'md', 'tsx'],
        include: [/\.md$/, /\.vue$/, /\.tsx$/],
        dts: resolve(__dirname, '../types/components.d.ts'),
        resolvers: [
            IconsResolver(),
            ElementPlusResolver(),
            VueUseComponentsResolver()
        ]
    }),
    // i18n 国际化支持
    UnpluginVueI18n({
        runtimeOnly: true,
        compositionOnly: true,
        include: [resolve(__dirname, '../../locales/**')],
    }),
    // 生产环境资源压缩
    viteCompression({
        // @ts-ignore
        algorithm: true,
    }),
])
